<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @cancel="handleCancel"
    cancelText="关闭">
    <template slot="footer">
      <a-button @click="handleConnect">测试连接</a-button>
      <a-button @click="handleCancel">关闭</a-button>
    </template>

    <collect-source-param-form ref="realForm" ></collect-source-param-form>
  </j-modal>
</template>

<script>


  import CollectSourceParamForm from './CollectSourceConfigForm'
  import { testSourceConn } from '@api/apiDs'
  export default {
    name: 'CollectSourceParamModal',
    components: {
      CollectSourceParamForm
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        recordId: '',
      }
    },
    methods: {
      edit (record) {
        this.recordId = record.tid
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.showConfig(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },

      handleCancel () {
        this.close()
      },
      handleConnect(){
        //测试连接
        this.testConn(null);
      },

      testConn(record){
        let param = {}
        if(record == null){
          param = {tid:this.recordId}
        }else{
          param = {tid:record.tid}
        }

        testSourceConn(param).then(res => {
          if (res.success) {
            console.log(res)
            this.$message.info("连接成功")
          } else {
            this.$message.warning(res.message)
          }
        })
      }
    }
  }
</script>